#include "DBQueryResult.h"

void DBQueryResult::SetFieldName(UINT colNum,string name)
{
	if (colNum>=m_FieldName.size())
		m_FieldName.push_back(name);
	else
		m_FieldName[colNum] = name;
}

string DBQueryResult::GetFieldName(UINT colIdx)
{
	if (colIdx>=m_FieldName.size())
		return "";
	return m_FieldName.at(colIdx);
}

UINT DBQueryResult::GetFieldIdx(string colName)
{
	m_FieldIter = ::find(m_FieldName.begin(),m_FieldName.end(),colName);
	if (m_FieldIter!=m_FieldName.end())
		return (UINT)(m_FieldIter - m_FieldName.begin());
	return 0;
}

void DBQueryResult::SetFieldValue(ULONGLONG rowIdx,FIELD_INFO *pField)
{
	m_Items.insert(ITEM_MAP::value_type(rowIdx,pField));
}

FIELD_INFO *DBQueryResult::GetFieldValue(ULONGLONG rowIdx,UINT colIdx)
{
	m_Range = m_Items.equal_range(rowIdx);
	for (m_Iter = m_Range.first;m_Iter!=m_Range.second;m_Iter++)
		if (m_Iter->second->m_colIdx==colIdx)
			return m_Iter->second;
	return 0;
}

FIELD_INFO *DBQueryResult::GetFieldValue(ULONGLONG rowIdx,string colName)
{
	return GetFieldValue(rowIdx,GetFieldIdx(colName));
}